<%@ page pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='lb' /></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <form name="totalForm" id="totalForm" action="${web_domain}/merchant/order/list" method="get">

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='ddbh' /></label>
                        <div class="layui-input-inline">
                            <input type="text" name="orderNo" placeholder="<fmt:message key='qsrddmc' />" value="<c:if test='${params.orderNo !=null}'>${params.orderNo}</c:if>" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='shr' /></label>
                        <div class="layui-input-inline">
                            <input type="text" name="deliveryName" placeholder="<fmt:message key='qsrshrmc' />" value="<c:if test='${params.deliveryName !=null}'>${params.deliveryName}</c:if>" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='sjh' /></label>
                        <div class="layui-input-inline">
                            <input type="text" name="deliveryMobile" placeholder="<fmt:message key='qsrshrmc' />" value="<c:if test='${params.deliveryMobile !=null}'>${params.deliveryMobile}</c:if>" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='shijian' /></label>
                        <div class="layui-input-inline" style="width:250px;">
                            <input type="text" id="feijin-begin-time" style="width:100px;" name="beginTime" placeholder="<fmt:message key='qrskssj' />" value="<c:if test='${params.beginTime !=null}'>${params.beginTime}</c:if>" autocomplete="off" class="layui-input"> -
                            <input type="text" id="feijin-end-time" style="width:100px;" name="endTime" placeholder="<fmt:message key='qsrjssj' />" value="<c:if test='${params.endTime !=null}'>${params.endTime}</c:if>" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <!-- 需要排序的字段 -->
                    <input type="hidden" class="feijin-orderby" name="orderByCreateTime" id="orderByCreateTimeParams" value="${params.orderByCreateTime}"/>
                    <input type="hidden" class="feijin-orderby" name="orderByPrice" id="orderByPriceParams" value="${params.orderByPrice}"/>
                    <!-- 需要排序的字段 -->

                    <input type="hidden" name="status" value="${params.status}"/>

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> <fmt:message key='ss' /></button>
                    </div>
                </form>
            </div>
        </div>

    </div>

    <div class="layui-card">
        <div class="layui-field-box layui-form">

            <a href="${web_domain}/merchant/order/exports?status=${params.status}&orderNo=${params.orderNo}&deliveryName=${params.deliveryName}&deliveryMobile=${params.deliveryMobile}&payMethod=${params.payMethod}&payStatus=${params.payStatus}" class="layui-btn layui-btn-sm" id="export"><i class="layui-icon">&#xe601;</i> <fmt:message key='dcdd' /></a>

            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li <c:if test="${params.status eq 0}">class="layui-this"</c:if>>
                        <a href="${web_domain}/merchant/order/list"
                           <c:if test="${params.status eq 0}">style="color: rgb(0, 150, 136)"</c:if> ><fmt:message key='qb' /></a>
                    </li>
                    <li <c:if test="${params.status eq 1}">class="layui-this"</c:if>>
                        <a href="${web_domain}/merchant/order/list?status=1" <c:if test="${params.status eq 1}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='wfk' /></a>
                    </li>
                    <li <c:if test="${params.status eq 2}">class="layui-this"</c:if>>
                        <a href="${web_domain}/merchant/order/list?status=2" <c:if test="${params.status eq 2}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='dfh' /></a>
                    </li>
                    <li <c:if test="${params.status eq 3}">class="layui-this"</c:if>>
                        <a href="${web_domain}/merchant/order/list?status=3" <c:if test="${params.status eq 3}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='dsh' /></a>
                    </li>
                    <li <c:if test="${params.status eq 4}">class="layui-this"</c:if>>
                        <a href="${web_domain}/merchant/order/list?status=4" <c:if test="${params.status eq 4}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='dpj' /></a>
                    </li>
                    <li <c:if test="${params.status eq 5}">class="layui-this"</c:if>>
                        <a href="${web_domain}/merchant/order/list?status=5" <c:if test="${params.status eq 5}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='ywc' /></a>
                    </li>
                    <li <c:if test="${params.status eq 6}">class="layui-this"</c:if>>
                        <a href="${web_domain}/merchant/order/list?status=6" <c:if test="${params.status eq 6}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='yquxiao' /></a>
                    </li>
                </ul>
            </div>


            <table class="layui-table" lay-size="sm">
                <thead>
                <tr>
                    <th><fmt:message key='xh' /></th>
                    <th><fmt:message key='ddbh' /></th>
                    <th><fmt:message key='ddly' /></th>
                    <th><fmt:message key='fxly' /></th>
                    <th><fmt:message key='ddlx' /></th>
                    <th id="orderByCreateTime">
                        <span><fmt:message key='xdsj' /></span>
                        <span class="layui-table-sort layui-inline" lay-sort="${params.orderByCreateTime}"><i class="layui-edge layui-table-sort-asc" title="<fmt:message key='sx' />"></i><i class="layui-edge layui-table-sort-desc" title="<fmt:message key='jx' />"></i></span>
                    </th>
                    <th><fmt:message key='shr' /></th>
                    <th><fmt:message key='dh' /></th>
                    <th><fmt:message key='shdz' /></th>
                    <th id="orderByPrice">
                        <span><fmt:message key='ddzj' /></span>
                        <span class="layui-table-sort layui-inline" lay-sort="${params.orderByPrice}"><i class="layui-edge layui-table-sort-asc" title="<fmt:message key='sx' />"></i><i class="layui-edge layui-table-sort-desc" title="<fmt:message key='jx' />"></i></span>
                    </th>
                    <th><fmt:message key='ddzt' /></th>
                    <th><fmt:message key='sfsh' /></th>
                    <th><fmt:message key='psfs' /></th>
                    <th><fmt:message key='cz' /></th>
                </tr>
                </thead>
                <c:forEach items="${page.result}" var="item" varStatus="status">
                    <tr>
                        <td>${status.index + 1 }</td>
                        <td>${item.orderNo }</td>
                        <c:choose>
                            <c:when test="${item.distributionOrder == 1}">
                                <td><fmt:message key='fxdd' /></td>
                                <td>
                                    <c:if test="${item.distributorSource == 1}"><fmt:message key='spfx' /></c:if>
                                    <c:if test="${item.distributorSource == 2}"><fmt:message key='wdfx' /></c:if>
                                    <c:if test="${item.distributorSource == 3}"><fmt:message key='scgm' /></c:if>
                                </td>
                            </c:when>
                            <c:otherwise>
                                <td><fmt:message key='scdd' /></td>
                                <td></td>
                            </c:otherwise>
                        </c:choose>
                        <td>
                            <c:choose>
                                <c:when test="${item.marketingType eq 0}"><fmt:message key='ptdd' /></c:when>
                                <c:when test="${item.marketingType eq 1}"><fmt:message key='zphddd' /></c:when>
                                <c:when test="${item.marketingType eq 2}"><fmt:message key='pthddd' /></c:when>
                                <c:when test="${item.marketingType eq 3}"><fmt:message key='tjhddd' /></c:when>
                                <c:when test="${item.marketingType eq 4}"><fmt:message key='mshddd' /></c:when>
                                <c:when test="${item.marketingType eq 5}"><fmt:message key='yshddd' /></c:when>
                            </c:choose>
                        </td>
                        <td><fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                        <td>${item.deliveryName}</td>
                        <td>${item.deliveryMobile}</td>
                        <td>${item.deliveryProvince}${item.deliveryCity}${item.deliveryArea}${item.deliveryAddress}</td>
                        <td><fmt:formatNumber value="${item.price}" type="CURRENCY"/></td>
                        <td>
                            <c:choose>
                                <c:when test="${item.status == 1}"><fmt:message key='dfk' /></c:when>
                                <c:when test="${item.status == 2}"><fmt:message key='dfh' /></c:when>
                                <c:when test="${item.status == 3}"><fmt:message key='dsh' /></c:when>
                                <c:when test="${item.status == 4}"><fmt:message key='dpj' /></c:when>
                                <c:when test="${item.status == 5}"><fmt:message key='jywc' /></c:when>
                                <c:when test="${item.status == 6}"><fmt:message key='ddqx' /></c:when>
                                <c:when test="${item.status == 7}"><fmt:message key='yzfysdj' /></c:when>
                                <c:when test="${item.status == 8}"><fmt:message key='dzfyswk' /></c:when>
                            </c:choose>
                        </td>
                        <td>
                            <c:if test="${item.isAfterSale == 1}">
                                <fmt:message key='s' />
                            </c:if>
                        </td>
                        <td>
                            <c:choose>
                                <c:when test="${item.shippingMethod == 1}"><fmt:message key='kd' /></c:when>
                                <c:when test="${item.shippingMethod == 2}"><fmt:message key='ziti' /></c:when>
                            </c:choose>
                        </td>
                        <td>
                            <div class="layui-btn-container">
                                <c:choose>
                                    <c:when test="${item.status eq 2 && item.isAfterSale != 1 && item.shippingMethod != 2}">
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-delivery"><fmt:message key='fahuo' /></a>
                                    </c:when>

                                    <c:when test="${item.status eq 2 && item.isAfterSale != 1 && item.shippingMethod == 2}">
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-shipping"><fmt:message key='th' /></a>
                                    </c:when>

                                    <c:when test="${item.status eq 1}">
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-modifyAmount"><fmt:message key='xgjg' /></a>
                                    </c:when>

                                </c:choose>

                                <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-detail"><fmt:message key='ck' /></a>
                            </div>
                        </td>
                    </tr>
                </c:forEach>
            </table>
            <jsp:include page="/commons/page.jsp" flush="true"/>
        </div>
    </div>

</div>

<script>


    layui.use(['form', 'laydate'], function () {

        var laydate = layui.laydate;

        laydate.render({
            elem: '#feijin-begin-time'
        });

        laydate.render({
            elem: '#feijin-end-time'
        });

    });

    $(function () {

        //查看详情
        $(".feijin-detail").click(function () {

            var id = $(this).attr("data-id");

            layer.open({
                type: 2
                , title: '<fmt:message key='ckxq' />'
                , content: '${web_domain}/merchant/order/' + id + '/detail'
                , maxmin: true
                , area: ['97%', '97%']
                , btn: ['<fmt:message key='fh' />']
            });
        });

        //发货
        $(".feijin-delivery").click(function () {

            var id = $(this).attr("data-id");

            layer.open({
                type: 2
                , title: '<fmt:message key='fahuo' />'
                , content: '${web_domain}/merchant/order/' + id + '/delivery'
                , maxmin: true
                , area: ['90%', '90%']
                , btn: ['<fmt:message key='fahuo' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        //提货
        $(".feijin-shipping").click(function () {

            var id = $(this).attr("data-id");

            layer.confirm('<fmt:message key='qrythm' />', {icon: 3, title: '<fmt:message key='ts' />'}, function (index) {
                $.ajax({
                    url: '${web_domain}/merchant/order/' + id + '/shipping',
                    type: "post",
                    dataType: "json",
                    data: {
                        "_method": "put"
                    },
                    success: function () {

                        layer.close(index);
                        location.reload();
                    }
                });
            });


        });

        //修改订单价格
        $(".feijin-modifyAmount").click(function () {

            var id = $(this).attr("data-id");

            layer.open({
                type: 2
                , title: '<fmt:message key='xgddzj' />'
                , content: '${web_domain}/merchant/order/' + id + '/modifyAmount'
                , maxmin: true
                , area: ['60%', '60%']
                , btn: ['<fmt:message key='xg' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        //按时间排序
        $("#orderByCreateTime").click(function () {
            $(".feijin-orderby").attr("value", "");
            var orderBy = "${params.orderByCreateTime}";

            if (orderBy == "asc") {
                $("#orderByCreateTimeParams").attr("value", "");
                $("#search").click();
                return;
            }

            if (orderBy == "desc") {
                $("#orderByCreateTimeParams").attr("value", "asc");
                $("#search").click();
                return;
            }

            if (orderBy == "") {
                $("#orderByCreateTimeParams").attr("value", "desc");
                $("#search").click();
                return;
            }
        });

        //按余额排序
        $("#orderByPrice").click(function () {
            $(".feijin-orderby").attr("value", "");
            var orderBy = "${params.orderByPrice}";

            if (orderBy == "asc") {
                $("#orderByPriceParams").attr("value", "");
                $("#search").click();
                return;
            }

            if (orderBy == "desc") {
                $("#orderByPriceParams").attr("value", "asc");
                $("#search").click();
                return;
            }

            if (orderBy == "") {
                $("#orderByPriceParams").attr("value", "desc");
                $("#search").click();
                return;
            }

        });

    });
</script>
</body>
</fmt:bundle>
</html>
